//<script language="javascript">
var applID = getParam("ApplID");
var soapCount=0;
var aPos,aEmpName,aFName,aLName;
var aspFile = "Application.aspx";
var SOAP = function(){};
var soap = new SOAP(aspFile);
var soap1 = new SOAP(aspFile+"?CoAppl=1");
var frmParent = getParentFrame();
var unloadMe = true;
		document.onmouseover = mouseover;
		document.onmouseout = mouseout;
		document.attachEvent("onkeydown",doEnterKey);
function page_Load(thread){
	initWS("APPL_INFO","Application.asmx?WSDL&ApplID="+applID);
	initPreset();
	initElements();
	//initBehaviors(findElementByAttr(document.body,"preset",undefined,true));
	//Locals
	function initBehaviors(es,index){
/***RETURN***/return;
		if( index == es.length )return;
		if( defined(index) )es[index].className = "mask";
		else index = -1;
		setTimeout(function(){initBehaviors(es,index+1)},100);
	}
	function initElements(tagNames){
		if( !tagNames )
			return initElements(new Array("INPUT","SELECT","TEXTAREA"));
		for( var t=0; t < tagNames.length; t++ ){
			var els = document.all.tags(tagNames[t]);
			for(var i=0; i < els.length; i++ ){
				if( els[i].onchange == null && !els[i].noonchange ){
					if( els[i].className == "mask" )els[i].onupdate = updateElement;
					else els[i].onchange = updateField;
				}
				if( !els[i].onfocus  )els[i].onfocus = function(){try{this.select()}catch(e){}};
			}
		}
	}
}
function reloadApplInfo(href,applID){
	if( href )frmParent.document.location = href;
	if( applID )frmParent.document.location = frmParent.document.location.href.replace(_applID(),applID);
	else frmParent.document.location.reload();
	unloadMe = false;
}
//********** Show Rows *************
function showAddrRow(el,spnTimeName){
	var inps = el.parentElement.parentElement.all.tags("INPUT");
	for( var i=0,j=0,n=0; i < inps.length; i++ )
		if( inps[i].time == 1 )
			n += parseFloat((inps[i].value.replace(/[\D]/g,"")||0)/Math.pow(12,j++));
	__fieldByName(el,"TimeLength",Math.round(n*10)/10);
	checkAddrRows(document.all[spnTimeName]);
}
function checkAddrRows(spnTime){
	for( var i=0,n=0; i < spnTime.length && n < 5; i++ )
		n += parseFloat(spnTime[i].innerText||0);
	if( !spnTime[0] )return;
	var tr = getParentByTag(spnTime[0],"tr");
	tr = document.all[tr.id];
	for( var m=0; m < tr.length; m++ )
		tr[m].style.display = m>=i || (m && parseFloat(spnTime[m-1].innerText)==0) ?"none":"";
}
//************ Updates  ************
function updateField_A(el,fieldName,fieldValue){
	clearTimeout(updateField_A.proc);
	setTimeout(function(){updateField(el,fieldName,fieldValue)},100);
}
function updateField(el,fieldName,fieldValue){
	if( !WS )return setTimeout(function(){updateField(el,fieldName,fieldValue)},300);
	el = el || event.srcElement;
	var fldName = defined(fieldName)?fieldName:(el.dataFld||el.dataField);
	var fldValue = defined(fieldValue)?fieldValue:getElementValue(el,true);
	var co = ws.createCallOptions(getDataSrc(el),undefined,false);
	var ret = WS(co,fldName,fldValue);
	if( showSOAPError(ret) )return false;
	if( !ret.value )return;
	if( !isNaN(ret.value) ){
		top.location.reload(top.location.href.replace("="+_applID(),"="+ret.value));
		return;
	}
	if( fldName.match(/FirstName/i) && ret.value && rsFromElement(el).State && rsFromElement(el).recordCount && !txtLastName1.value )try{txtLastName1.value = ret.value;}catch(e){}
}
function updateTable(el){
	if( !WS )return setTimeout(function(){updateField(el,fieldName,fieldValue)},300);
	el = el || event.srcElement;
	var fldName = el.dataFld;
	var fldValue = getElementValue(el,true);
	var index = getParentTR(el).rowIndex-1;
	var dataSrc = getDataSrc(el);
	var co = ws.createCallOptions(dataSrc,undefined,false);
	var ret = WS(co,index,fldName,fldValue);
	showSOAPError(ret);
}
function UpdateTable(el){return updateTable(el);}
function reloadCoX(){/**----->**/return;
	var ret = WS(CO("RemoveCoApplicant"));
	dcApplicant1.src = aspFile+"?dcApplicant1()";
	dcEmployments1.src = aspFile+"?dcEmployments1()";
	if( true || !_isDimok() )return;
	if( dcApplicant1.recordset.EOF )
		dcApplicant1.recordset.AddNew();
}
function remCoAppl(){if( !confirm("Remove Co-Applicant from application?") )return;
var ret =	WS(CO("RemoveCoApplicant"));
	if( showSOAPError(ret) )return;
	if( _rsApplInfoCo().recordcount > 0 ){
		_rsApplInfoCo().moveFirst();
		_rsApplInfoCo().Delete();
	}
	var els = selectElementsByAttributeEx(document,"dataSrc","#xmlApplInfoCo");
	for(var i=0,s=""; i < els.length; i++ )
		s += " "+els[i].dataFld+'=""'; 
	xmlApplInfoCo.loadXML("<DS><Table"+s+"/></DS>");
}
//*************** DTEC ***************
function getDTEC(){
var ret =	sendRequestXMLEx(aspFile,"getDTEC",txtSSN.value);
	if( !ret )return;
	var pers = eval(ret);
	if( !pers )return alert("No credit info found!");
	aFName = new Array();
	aLName = new Array();
	for( var i=0; i < pers.length; i++ ){
		aLName.push(pers[i].lastName);
		aFName.push(pers[i].firstName);
	}
	if( !txtLastName.value || !txtFirstName.value){
		txtLastName.value = aLName[0];
		txtFirstName.value = aFName[0];
		updateElement(txtLastName);
		updateElement(txtFirstName);
//		soap.updateElement(txtLastName,undefined,getFieldNameFromDataFld(txtFirstName),txtFirstName.value);
	}
	txtFirstName.focus();
}
//*************** ZIP ****************
function findCoChild(el,id){
	for( ; el; el = el.parentElement )
		if( el.all[id] )return el.all[id];
	return null;
}
function getCityNode(el){return findCoChild(el,"txtCity"); }
function getCitySel(el){return findCoChild(el,"selCity"); }
function getStateNode(el){return findCoChild(el,"txtState"); }
function onZipPress(txtZip,thread){
	if( !thread ){
		clearTimeout(onZipPress.proc);
		return onZipPress.proc = setTimeout(function(){onZipPress(txtZip,true)},100);
	}
	if( txtZip.value.match(/\D/) )return txtZip.value = txtZip.value.replace(/\D/g,"");
	if( txtZip.value.length < 5 )return;
//	var elCity = getCityNode(txtZip);
//	if( !elCity )return;
//	elCity.value = "*** Loading Cities ***";
//	elCity.style.display = "";
//	getCitySel(txtZip).style.display = "none";
//	getStateNode(txtZip).value = "XX";
		loadZIP(txtZip);
//	selHomeYears[getElementIndex(txtZip)].focus();
}
function loadZIP(txtZip,rowOrChild){
	WS(onLoadZIP,"GetStateByZip",txtZip.value);
}
function onLoadZIP(ret){
	if( showSOAPError(ret) )return txtZip.focus();
	var rs = xmlAddrInfo.recordset;
	rs.moveFirst()
	rs("StateCode").value = ret.value;
}
//**********************************************
function _isDimok(){ return userName.match(/dimok/i) ? true : false };
// ***** properties *****
function _applID(){return getParamInt("ApplID")}
function _rsApplInfoCo(){return xmlApplInfoCo.recordset}